<script>
	export default {
		onLaunch: function() {
			// #ifndef H5
			// plus.globalEvent.addEventListener('newintent', (e) => {
			// 	this.checkArguments(); // 检测启动参数  
			// });
			// #endif
		},
		onShow: function() {
			// #ifndef H5
			this.checkArguments();
			// #endif
		},
		onHide: function() {},
		created() {
			// const clientInfo = plus.push.getClientInfo()
			// console.log(clientInfo)
			// uni.showModal({
			//     title: '提示',
			//     content: '123123',
			//     success: function (res) {
			//         if (res.confirm) {
			//             console.log('用户点击确定');
			//         } else if (res.cancel) {
			//             console.log('用户点击取消');
			//         }
			//     }
			// });
			uni.request({
				url: uni.baseURL + '/boot/bankCard/remind',
				header: {
					token: uni.getStorageSync('token')
				},
				success: (res) => {
					if (res.data.success == 1) {
						if (res.data.data.remind == 'yes') {
							this.tes(res.data.data.content)
						}
					}
				}
			});

		},
		methods: {
			tes(content) {
				var main = plus.android.runtimeMainActivity();
				var pkName = main.getPackageName();
				var uid = main.getApplicationInfo().plusGetAttribute("uid");
				//var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
				//android.support.v4升级为androidx
				var NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
				var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
				// 未开通‘允许通知’权限，则弹窗提醒开通，并点击确认后，跳转到系统设置页面进行设置
				if (!areNotificationsEnabled) {
					uni.showModal({
						title: '通知权限开启提醒',
						content: '您还没有开启通知权限，无法接受到消息通知，请前往设置！',
						showCancel: true,
						confirmText: '去设置',
						cancelText: '取消',
						success: function(res) {
							if (res.confirm) {
								var Intent = plus.android.importClass('android.content.Intent');
								var Build = plus.android.importClass("android.os.Build");
								//android 8.0引导
								if (Build.VERSION.SDK_INT >= 26) {
									var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
									intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
								} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0
									var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
									intent.putExtra("app_package", pkName);
									intent.putExtra("app_uid", uid);
								} else { //(<21)其他--跳转到该应用管理的详情页
									intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
									var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
									intent.setData(uri);
								}
								// 跳转到该应用的系统通知设置页
								main.startActivity(intent);
							}
						}
					});
				} else {
					var content = content;
					var options = {
						"cover": true, // 覆盖上次
						"when": new Date(),
						'title': "儒雅牛账单提醒"
					};

					var body = {
						'id': 'id',
						'key2': "key2"
					}
					var payload = JSON.stringify(body);
					plus.push.createMessage(content, payload, options);
				}
			},
			checkArguments() {
				var args = plus.runtime.arguments;
				let sherUrl = args;
				if (sherUrl) {
					if (sherUrl.substr(0, 10) === 'ruyaniu://') {
						let openUrl = decodeURIComponent(sherUrl.substr(10));
						let openUrlArr = openUrl.split(',')
						plus.runtime.arguments = null;
						plus.runtime.arguments = ''
						console.log(openUrlArr)
						if (openUrlArr[1] == 1) {
							uni.navigateTo({
								url: '/pages/index/Taobaodetail/Taobaodetail?id=' + openUrlArr[0] +
									'&invitacode=' + openUrlArr[2]
							});
						}
						if (openUrlArr[1] == 2) {
							uni.navigateTo({
								url: '/pages/index/JDdetail/JDdetail?id=' + openUrlArr[0] + '&invitacode=' +
									openUrlArr[2]
							});
						}
						if (openUrlArr[1] == 3) {
							uni.navigateTo({
								url: '/pages/index/Vipshopdetail/Vipshopdetail?id=' + openUrlArr[0] +
									'&invitacode=' + openUrlArr[2]
							});
						}
						if (openUrlArr[1] == 4) {
							uni.navigateTo({
								url: '/pages/index/detail/detail?id=' + openUrlArr[0] +
									'&invitacode=' + openUrlArr[2]
							});
						}
						
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import "common/demo.scss";
</style>
